<ui:composition xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core"
	template="template/template.xhtml">
	<ui:define name="title">
		<h:outputText value="#{msgs.analyticalPrioritization}"/>
	</ui:define>
	<ui:define name="bodyInclude">
		<ui:include src="include/menu.xhtml" />
		<h:form id="analyticalPrioritizationForm">
			<p:fieldset collapsed="#{analyticalPrioritizationController.iterationCompleted}" id="matrixFieldset" legend="#{msgs.analyticalPrioritization}: #{analyticalPrioritizationController.currentPrioritization.project.name} - #{analyticalPrioritizationController.currentPrioritization.version.name} - #{analyticalPrioritizationController.currentPrioritization.criterionTypeTranslation}" styleClass="right" toggleable="true" toggleSpeed="300">
				<p:commandButton alt="#{msgs.referenceTable}" image="ui-icon ui-icon-help" onclick="dialogReferenceTableVar.show()" styleClass="helpButton" type="button" title="#{msgs.referenceTable}" value="#{msgs.referenceTable}" />
				<p:outputPanel layout="block" styleClass="center container">
					<h:panelGrid cellpadding="0" cellspacing="0" columns="2">
						<h:panelGroup />
						<p:outputPanel layout="block">
							<h:panelGrid columns="#{analyticalPrioritizationController.scriptsContainedInMatrixSize}" >
								<c:forEach items="#{analyticalPrioritizationController.scriptsNames}" var="scriptName" >
									<h:outputText styleClass="comparisonMatrixTopHeaderCell" value="#{scriptName}" />
								</c:forEach>
							</h:panelGrid>
						</p:outputPanel>
						<p:outputPanel layout="block">
							<h:panelGrid cellpadding="0" cellspacing="0" columns="1" >
								<c:forEach items="#{analyticalPrioritizationController.scriptsNames}" var="scriptName">
									<h:outputText styleClass="comparisonMatrixLeftHeaderCell" value="#{scriptName}" />
								</c:forEach>
							</h:panelGrid>
						</p:outputPanel>
						<p:outputPanel layout="block">
							<p:dataGrid columns="#{analyticalPrioritizationController.scriptsContainedInMatrixSize}" id="ahpDataGrid" paginator="false" rows="#{fn:length(analyticalPrioritizationController.comparisonMatrix)}" value="#{analyticalPrioritizationController.comparisonMatrix}" var="script">
								<p:column styleClass="noPadding">
									<p:outputPanel layout="block" styleClass="comparisonMatrixCell" >
										<h:outputText rendered="#{script.firstScript == script.secondScript or analyticalPrioritizationController.comparisonMatrixComplete}" styleClass="bold" value="#{script.value}"/>
										<p:inplace editor="false" effect="slide" effectSpeed="fast" emptyLabel=" - " rendered="#{script.firstScript != script.secondScript and not analyticalPrioritizationController.comparisonMatrixComplete}" widgetVar="cellInplace#{script.comparisonMatrixItemId}">											
											<p:inputText size="1" value="#{script.value}"/>
											<p:commandButton action="#{analyticalPrioritizationController.onCellUpdate}" ajax="true" alt="#{msgs.updateValue}" image="ui-icon ui-icon-check" oncomplete="cellInplace#{script.comparisonMatrixItemId}.hide()" process="@parent" title="#{msgs.updateValue}" update="analyticalPrioritizationForm:ahpDataGrid analyticalPrioritizationForm:prioritizeButton">
												<f:setPropertyActionListener target="#{analyticalPrioritizationController.currentEditedMatrixItem}" value="#{script}" />
											</p:commandButton>
										</p:inplace>
									</p:outputPanel>
								</p:column>
							</p:dataGrid>
						</p:outputPanel>
					</h:panelGrid>
					<p:outputPanel layout="block" styleClass="buttonContainer center">
						<p:commandButton action="#{analyticalPrioritizationController.onPrioritization}" alt="#{msgs.prioritize}" id="prioritizeButton" image="ui-icon ui-icon-calculator" process="@this" rendered="#{analyticalPrioritizationController.comparisonMatrixComplete}" title="#{msgs.prioritize}" update="@form" value="#{msgs.prioritize}" />
					</p:outputPanel>
				</p:outputPanel>
			</p:fieldset>
			<p:fieldset id="resultFieldset" legend="#{msgs.results}: #{analyticalPrioritizationController.currentPrioritization.project.name} - #{analyticalPrioritizationController.currentPrioritization.version.name} - #{analyticalPrioritizationController.currentPrioritization.criterionTypeTranslation}" rendered="#{analyticalPrioritizationController.iterationCompleted}" toggleable="true" toggleSpeed="300">
				<p:outputPanel layout="block" styleClass="center container">
					<h:panelGrid cellpadding="5" columns="4">
						<h:outputText styleClass="bold" value="#{msgs.consistencyIndex}: "/>
						<h:outputText value="#{analyticalPrioritizationController.currentPrioritization.consistencyIndex}" />
						<h:outputText styleClass="bold" value="#{msgs.consistencyRatio}: "/>
						<h:outputText value="#{analyticalPrioritizationController.consistencyRation}">
							<f:convertNumber maxFractionDigits="2"/>
						</h:outputText>
					</h:panelGrid>
					<p:dataTable currentPageReportTemplate="{currentPage} #{msgs.of} {totalPages}" emptyMessage="#{msgs.emptyDataTableMessage}" id="matrixResultsTable" paginator="true" paginatorAlwaysVisible="false" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport}{PageLinks}{NextPageLink} {LastPageLink}" rows="10" rowsPerPageTemplate="5,10,20,50" value="#{analyticalPrioritizationController.comparisonMatrixResults}" var="result">
						<p:column headerText="#{msgs.script}" sortBy="#{result.scriptLabel}" styleClass="center">
							<h:outputText value="#{result.scriptLabel}"/>
						</p:column>
						<p:column headerText="#{msgs.percentageOfImportance}" sortBy="#{result.percentage}" styleClass="center">
							<h:outputText value="#{result.percentage}">
								<f:convertNumber type="percent" />
							</h:outputText>
						</p:column>
					</p:dataTable>
				</p:outputPanel>
			</p:fieldset>
		</h:form>
		<ui:include src="dialog/dialogReferenceTable.xhtml" />
	</ui:define>
</ui:composition>				